﻿#region Namespaces

using System.Collections.Generic;
using System.Text;

#endregion

namespace Vibstudio.X4NET.Collections
{
    public abstract class ResultCollectionBase<T> : List<T>
    {
        public abstract bool ThereAreErrors { get; }

        protected abstract IList<string> Errors { get; }

        protected string FlatErrors
        {
            get
            {
                var builder = new StringBuilder();

                if (Errors.Count == 1)
                {
                    builder.Append(Errors[0]);
                }
                else if (Errors.Count > 1)
                {
                    for (int i = 0; i < Errors.Count; i++)
                    {
                        builder.AppendFormat(
                                             Errors[i].Substring(Errors[i].Length - 1) == "\n" ? "{0}. {1}\n" : "{0}. {1}\n\n",
                                             i + 1,
                                             Errors[i]);
                    }
                }

                return builder.ToString();
            }
        }
    }
}